﻿using PKTools.Database;
using PKTools.Scheduler;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Scheduler
{
    partial class JobStep : IJobStep
    {
        public IJobStep GetNextStep()
        {
            var
                next = this.Job.JobStepList.OrderBy(e => e.Sequence).FirstOrDefault(e => e.Sequence > this.Sequence);

            return next;
        }

        public IJob GetJob()
        {
            return this.Job;
        }

        public bool GetStopJob()
        {
            return this.StopJob;
        }

        public void CreateTask()
        {
            var
                jobTask = new JobTask
                {
                    JobStepID = this.ID,
                    EET = this.Job.NEET.Value,
                    Executing = false,
                    Attempts = 0,
                    Retries = this.RetryCount
                };

            Sql.Context.Insert(jobTask);
        }
    }
}
